<%= form_for [:admin, @user_info], :validate => true do |f| %>

<%= render "shared/error_messages", :target => @user_info %>

  <h2>Osobní údaje</h2>

  <table>
    <tbody>
      <tr>
        <th><%= f.label :name %></th>
        <td><%= f.text_field :name, :size => 30, :maxlength => 15 %></td>
      </tr>
      <tr>
        <th><%= f.label :surname %></th>
        <td><%= f.text_field :surname, :size => 30, :maxlength => 30 %></td>
      </tr>
      <%= f.fields_for :user, :validate => true do |user| %>
      <tr>
        <th><%= user.label :email %></th>
        <td><%= user.text_field :email, :maxlength => 50, :size => 30 %></td>
      </tr>
      <% end %>
      <tr>
        <th><%= f.label :phone %></th>
        <td><%= f.text_field :phone %></td>
      </tr>
      <%= f.fields_for :user, :validate => false do |user| %>
      <tr>
        <th><%= user.label :discount %></th>
        <td><%= user.text_field :discount, :maxlength => 2, :size => 4 %>&nbsp;%</td>
      </tr>
      <% end %>
    </tbody>
  </table>

  <h2>Registrační údaje</h2>

  <%= f.fields_for :user, :validate => false do |user| %>
    <table>
      <tbody>
        <tr>
          <th><%= user.label :password %></th>
          <td><%= user.password_field :password, :maxlength => 20, :size => 25 %></td>
        </tr>
        <tr>
          <th><%= user.label :password_confirmation %></th>
          <td><%= user.password_field :password_confirmation, :maxlength => 20, :size => 25 %></td>
        </tr>
      </tbody>
    </table>
  <% end %>

  <h2>Firma (nepovinné)</h2>

  <p>
    <%= f.check_box :ignore_company, :onchange => "document.getElementById('company').style.display = (this.checked ? 'none' : 'block');" %>
    <%= f.label :ignore_company %>
  </p>

  <%= f.fields_for :company, :validate => false do |company| %>
    <table id="company" style="<% if @user_info.ignore_company == '1' %>display:none;<% end %>">
      <tbody>
        <tr>
          <th><%= company.label :name %></th>
          <td><%= company.text_field :name, :maxlength => 30 %></td>
        </tr>
        <tr>
          <th><%= company.label :ico %></th>
          <td><%= company.text_field :ico, :maxlength => 13 %></td>
        </tr>
        <tr>
          <th><%= company.label :dic %></th>
          <td><%= company.text_field :dic, :maxlength => 13 %></td>
        </tr>
        <tr>
          <th><%= company.label :phone %></th>
          <td><%= company.text_field :phone, :maxlength => 16 %></td>
        </tr>
      </tbody>
    </table>
  <% end %>

  <h2>Doručovací adresa</h2>
  
  <%= f.fields_for :shipping_address do |address| %>
    <table>
      <tbody>
        <tr>
          <th><%= address.label :street %></th>
          <td><%= address.text_field :street %></td>
        </tr>
        <tr>
          <th><%= address.label :city %></th>
          <td><%= address.text_field :city %></td>
        </tr>
        <tr>
          <th><%= address.label :zip %></th>
          <td><%= address.text_field :zip %></td>
        </tr>
      </tbody>
    </table>
  <% end %>

  <%= f.fields_for :billing_address, :validate => false do |address| %>
    <h2>Fakturační adresa</h2>

    <p>
      <%= f.check_box :use_billing_address, :onchange => "document.getElementById('billing_address').style.display = (this.checked ? 'none' : 'block');" %>
      <%= f.label :use_billing_address %>
    </p>

    <table id="billing_address" style="<% if @user_info.use_billing_address == '1' %>display:none;<% end %>">
      <tbody>
        <tr>
          <th><%= address.label :street %></th>
          <td><%= address.text_field :street %></td>
        </tr>
        <tr>
          <th><%= address.label :city %></th>
          <td><%= address.text_field :city %></td>
        </tr>
        <tr>
          <th><%= address.label :zip %></th>
          <td><%= address.text_field :zip %></td>
        </tr>
      </tbody>
    </table>
  <% end %>

  <%= f.submit %>
<% end %>